import json

from car.models import Car


def transform_keywords(carname):
    car = Car.objects.get(carname=carname)
    print(car.key_word)
    # 确保key_word是一个字典类型再进行转换
    if isinstance(car.key_word, str):
        # 尝试将字符串转换为字典
        try:
            key_words = eval(car.key_word)
            keyword_list = [{'name': name, 'value': value} for name, value in key_words.items()]
            return keyword_list
        except:
            print("Error converting string to dictionary.")
            return []





